<?php
/**
 * Created by PhpStorm.
 * User: user
 * Date: 2016/3/21
 * Time: 14:34
 */

namespace front\modules\app\controllers;


use front\controllers\WebBaseController;
use order\services\RepairMapService;
use Yii;
use yii\filters\VerbFilter;

class RepairmapController extends WebBaseController
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'create' => ['post'],
                    'changestatus' => ['post'],
                    'express' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Creates a new RepairMap model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
//        $data = [
//            'order_id' => 177,
//            'product_id' => 1601104322,
//            'customer_id' => 1234,
//        ];
    public function actionCreate()
    {
        $data = Yii::$app->request->post();

        $model = new RepairMapService();
        $result = $model->add($data);
        WebBaseController::getAjaxData(1,'获取成功', $result);
    }

    /**
     * Updates an existing RepairMap model.
     * If update is successful, the browser will be redirected to the 'view' page.
     *
     * @param data
     * @return mixed
     */
    //        $data = [
//            'id' => 2,
//            'status' => 4
//        ];
    public function actionChangestatus()
    {
        $data = Yii::$app->request->post();

        $model = new RepairMapService();

        $result = $model->changeStatus($data);

        WebBaseController::getAjaxData(1,'获取成功', $result);
    }

    /**
     * 修理完后
     * 顾客传快递信息
     * @param data
     * @return mixed
     */
//          $data = [
//            'id' => 1,
//            'express' => [
//                'name' => '小蜜蜂',
//                'district' => 1013,
//                'address' => '宜山路1000号518室',
//                'tel' => '13112345678',
//                'mobile' => '56131214',
//            ]
//        ];
    public function actionExpress()
    {
        $data = Yii::$app->request->post();

        $model = new RepairMapService();

        $result = $model->express($data);

        WebBaseController::getAjaxData(1,'获取成功', $result);
    }

    /**
     * 维修单查询
     * @param data
     * @return mixed
     */
    public function actionSearch() {
        $data = Yii::$app->request->get();

        $result = RepairMapService::search($data);

        WebBaseController::getAjaxData(1,'获取成功', $result);
    }
}